package com.example.demo.webSocketDemo;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
 
/**
 * @author qx
 * @date 2023/8/22
 * @des WebSocket配置类
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebMvcConfigurer, WebSocketConfigurer {
 
    @Autowired
    private SystemWebSocketHandler handler;
 
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 设置WebSocket服务器地址 ws://localhost:8080/SpringBootWebSocket
        registry.addHandler(handler, "/SpringBootWebSocket").setAllowedOrigins("*");
    }
}